"""
Checks that Pylint does not complain about various
methods on Django model fields.
"""
#  pylint: disable=C0111
from __future__ import print_function
from datetime import datetime, date
from decimal import Decimal
from django.db import models
from django.db.models import ForeignKey, OneToOneField


class LotsOfFieldsModel(models.Model):

    bigintegerfield = models.BigIntegerField()
    booleanfield = models.BooleanField(default=True)
    charfield = models.CharField(max_length=40, null=True)
    commaseparatedintegerfield = models.CommaSeparatedIntegerField()
    datetimefield = models.DateTimeField(auto_now_add=True)
    datefield = models.DateField(auto_now_add=True)
    decimalfield = models.DecimalField(max_digits=5, decimal_places=2)
    emailfield = models.EmailField()
    filefield = models.FileField(name='test_file', upload_to='test')
    filepathfield = models.FilePathField()
    floatfield = models.FloatField()
    genericipaddressfield = models.GenericIPAddressField()
    imagefield = models.ImageField(name='test_image', upload_to='test')
    ipaddressfield = models.IPAddressField()
    intfield = models.IntegerField(null=True)
    nullbooleanfield = models.NullBooleanField()
    positiveintegerfield = models.PositiveIntegerField()
    positivesmallintegerfield = models.PositiveSmallIntegerField()
    slugfield = models.SlugField()
    smallintegerfield = models.SmallIntegerField()
    textfield = models.TextField()
    timefield = models.TimeField()
    urlfield = models.URLField()

    def boolean_field_tests(self):
        print(self.booleanfield | True)
        print(self.nullbooleanfield | True)

    def string_field_tests(self):
        print(self.charfield.strip())
        print(self.charfield.upper())
        print(self.charfield.replace('x', 'y'))

        print(self.filepathfield.strip())
        print(self.filepathfield.upper())
        print(self.filepathfield.replace('x', 'y'))

        print(self.emailfield.strip())
        print(self.emailfield.upper())
        print(self.emailfield.replace('x', 'y'))

        print(self.textfield.strip())
        print(self.textfield.upper())
        print(self.textfield.replace('x', 'y'))

    def datetimefield_tests(self):
        now = datetime.now()
        print(now - self.datetimefield)
        print(self.datetimefield.ctime())

    def datefield_tests(self):
        now = date.today()
        print(now - self.datefield)
        print(self.datefield.isoformat())

    def decimalfield_tests(self):
        print(self.decimalfield.compare(Decimal('1.4')))

    def filefield_tests(self):
        print(self.filefield.file)
        print(self.imagefield.file)

    def numberfield_tests(self):
        print(self.intfield + 5)
        print(self.bigintegerfield + 4)
        print(self.smallintegerfield + 3)
        print(self.positiveintegerfield + 2)
        print(self.positivesmallintegerfield + 1)


class SomeModel(models.Model):
    pass


class Author(models.Model):
    author_name = models.CharField(max_length=100)


class ISBN(models.Model):
    value = models.CharField(max_length=100)


class Book(models.Model):
    book_name = models.CharField(max_length=100)
    author = models.ForeignKey(Author)
    isbn = models.OneToOneField(ISBN)

    def get_isbn(self):
        return self.isbn.value

    def get_author_name(self):
        return self.author.author_name


class Fruit(models.Model):
    fruit_name = models.CharField(max_length=20)


class Seed(models.Model):
    fruit = ForeignKey(Fruit)

    def get_fruit_name(self):
        return self.fruit.fruit_name


class User(models.Model):
    username = models.CharField(max_length=32)


class UserProfile(models.Model):
    user = OneToOneField(User)

    def get_username(self):
        return self.user.username


if __name__ == '__main__':
    MODEL = SomeModel()
    MODEL.save()
    MODEL.delete()

    COUNT = SomeModel.objects.count()
